//
//  RefreshView.m
//  xpkc
//
//  Created by TopSageOSX on 14-9-5.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "RefreshView.h"

@implementation RefreshView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self creatView];
        self.userInteractionEnabled = NO;
    }
    return self;
}
-(id)init{
    self = [super init];
    if (self) {
        //
        CGRect frame;
        if (isPad) {
            frame = CGRectMake(SCREEN_WIDTH/3, SCREEN_HEIGHT/4, SCREEN_WIDTH/3, SCREEN_WIDTH/4.5);
        }else if (SCREEN_WIDTH/SCREEN_HEIGHT==320/480){
            //4
            frame = CGRectMake(SCREEN_WIDTH/4, SCREEN_WIDTH/4, SCREEN_WIDTH/2, SCREEN_WIDTH/3);
        }else{
            frame = CGRectMake(SCREEN_WIDTH/4, SCREEN_HEIGHT/4, SCREEN_WIDTH/2, SCREEN_WIDTH/3);
        }
        self.frame = frame;
        [self creatView];
    }
    return self;
}
-(void)creatView{
    self.noteLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width/2, self.frame.size.height)];
    self.noteLabel.text = @"加载中";
    self.noteLabel.textColor = [UIColor darkGrayColor];
    self.noteLabel.textAlignment = NSTextAlignmentCenter;
    self.noteLabel.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.9];
    self.layer.cornerRadius = 6;
    [self addSubview:self.noteLabel];
    
    NSMutableArray *imagearray = [[NSMutableArray alloc]init];
    for (int i = 1; i<=20; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%02d.png",i]];
        [imagearray addObject:image];
    }
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.frame.size.width*4/7, self.frame.size.height/5, self.frame.size.width/3, self.frame.size.height/2)];
    self.imageView.animationImages = imagearray;
    self.imageView.animationRepeatCount = 0;
    self.imageView.animationDuration = 2;
    [self addSubview:self.imageView];
    self.hidden = YES;
    
}
-(void)startRefresh{
    self.hidden = NO;
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [self.imageView startAnimating];
}
-(void)endRefresh{
    self.hidden = YES;
    self.noteLabel.text = @"加载中";
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    [self.imageView stopAnimating];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
